import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author caiwl
 * @date 2020/5/25 14:32
 */
public class LogMain {
    public static void main(String[] args) {
        String path = "C:\\Users\\59466\\Documents\\WeChat Files\\LiteratureDragon88\\FileStorage\\File\\2020-01\\新建文件夹\\";
        String date = "2020-01-11";
        String fileName = path  + "platform_info-" + date + "-0].log";
        try {
            FileReader fr = new FileReader(fileName);
            BufferedReader bf = new BufferedReader(fr);
            String str;
            JsonParser parser = new JsonParser();
            JsonObject arg;
            JsonObject user;
            // 按行读取字符串
            System.out.println("申请人姓名,身份证号码,区域,产品,申请流水号,申请时间");
            while ((str = bf.readLine()) != null) {
                if (str.contains("/dataApiPlatform//treatment/underwrite/cognitive/r")) {
                    str = str.substring(str.indexOf("args=") + 5, str.indexOf(",timestamp="));
                    if (str.contains(",\"productNum\":\"gszj001\"")) {
                        arg = parser.parse(str).getAsJsonObject();
                        user = arg.get("users").getAsJsonArray().get(0).getAsJsonObject();
                        str = user.get("name").getAsString() + "," + user.get("certNum").getAsString() + "," + arg.get("area").getAsString() + "," + arg.get("productNum").getAsString() + "," + arg.get("lsh").getAsString() + "," + date;
                        System.out.println(str);
                    }
                }
            }
            bf.close();
            fr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
